﻿using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MvcSample.Infrastructure.TagHelpers
{
    [OutputElementHint("ul")]
    public class ViewContextTagHelper
        : TagHelper
    {
        [HtmlAttributeNotBound]
        public ViewContext ViewContext { get; set; }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.PreContent.SetHtmlContent("<ul>");

            var sb = new StringBuilder();
            foreach (var key in ViewContext.ViewData.Keys)
            {
                var viewData = ViewContext.ViewData[key];
                sb.AppendFormat($"<li>{viewData.ToString()}---{key}</li>");
            }

            output.Content.SetHtmlContent(sb.ToString());
            output.PostContent.SetHtmlContent("</ul>");
        }
    }
}
